# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=knative-client
pkgver=1.14.0
pkgrel=0
pkgdesc="CLI client for Knative the serverless container platform in Kubernetes"
url="https://knative.dev/"
arch="all"
license="Apache-2.0"
makedepends="go"
checkdepends="bash"
subpackages="$pkgname-bash-completion $pkgname-zsh-completion"
source="https://github.com/knative/client/archive/refs/tags/knative-v$pkgver.tar.gz"
builddir="$srcdir/client-knative-v$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local _goldflags="
	-X knative.dev/client/pkg/kn/commands/version.Version=v$pkgver
	-X knative.dev/client/pkg/kn/commands/version.GitRevision=AlpineLinux
	-X 'knative.dev/client/pkg/kn/commands/version.BuildDate=$(date -u "+%Y-%m-%d %H:%M:%S" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})'
	"

	go build -v -ldflags "$_goldflags" ./cmd/kn/

	for shell in bash zsh; do
		./kn completion $shell > kn.$shell
	done
}

check() {
	# knative.dev/client/pkg/kn/plugin/verify_test.go needs to access itself during test
	GOFLAGS="${GOFLAGS/-trimpath/}" go test ./...
}

package() {
	install -Dm755 kn -t "$pkgdir"/usr/bin/

	install -Dm644 kn.bash \
		"$pkgdir"/usr/share/bash-completion/completions/kn
	install -Dm644 kn.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_kn
}

sha512sums="
ead9c964183347b40db32f29e4cd8a45e57474eb1f184688e16ddafb6ddf1c82c59899845ca6380243ac1cef775943f508d608d1add76c1be7ab00133b03554d  knative-v1.14.0.tar.gz
"
